/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package observer;

import commonSources.Painel;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Filipe
 */
public class LogSubject {

    private List<IObserver> observerList = new ArrayList<IObserver>();
    private Painel state;

    public LogSubject() {
    }

    public Painel getState() {
        return state;
    }

    public void attach(IObserver observer) {
        observerList.add(observer);
    }

    public void detach(IObserver observer) {
        observerList.remove(observer);
    }

    public void setState(Painel state) {
        this.state = state;
        stateChanged();
    }

    private void stateChanged() {
        for (IObserver item : observerList) {
            item.update(getState());
        }
    }
}
